import util from '../../../../utils/util';

const app = getApp()

Page({
  data: {
    noticelist:[],
	pageNum: 1, // 当前页码
	pageSize: 10, // 每页数量
	orderBy: 'create_time desc',
	hasMore: true // 是否还有更多数据
  },

  onLoad() {
    // var that = this;
    this.getNoticelist();
	},
	onShow(){
	  var that = this;
	  
	},
	onReachBottom() {
		var that = this;
		if(this.data.hasMore) {
			that.data.pageNum++;
			this.getNoticelist();
		}
		
	},
	getNoticelist(){
		var that = this;
		var noticeList = this.data.noticelist;
		util.get(`loadNotice?pageNum=${that.data.pageNum}&pageSize=${that.data.pageSize}&orderBy=${that.data.orderBy}`,response=>{
		  // TIPS: 为0不一般是失败么
		  if (response) {
			  wx.showToast({title: '加载中...',icon: 'loading',duration:1000});
			  noticeList = noticeList.concat(response.data);
		      that.setData({
				  noticelist: noticeList
			  });
			  if(noticeList.length >= response.total) {
				  that.setData({
					  hasMore: false
				  });
			  }
		  }
		})
	}

})
